/* eslint-disable no-unused-vars */
/* eslint-disable react-hooks/rules-of-hooks */
/* eslint-disable react-refresh/only-export-components */
import React, { useState } from "react";
import HocLogin from "../../../hook/HocLogin";
import styles from "./css/home.module.css";
import { ResultPage, Card, Button, Popup, CalendarPickerView } from "antd-mobile";
import { LoopOutline } from "antd-mobile-icons";
import { useDispatch, useSelector } from "react-redux";
import { jh, setDate } from "../../../store/slice/ticketSlice";
import { useNavigate } from "react-router-dom";
function index() {
  const start = useSelector((store) => store.ticket.start);
  const end = useSelector((store) => store.ticket.end);
  const date = useSelector((store) => store.ticket.date);
  const isSpeed = useSelector((store) => store.ticket.isSpeed);
  const dispatch = useDispatch();
  let nav = useNavigate();
   const [visible5, setVisible5] = useState(false)
  return (
    <div>
      <ResultPage status="" title="" description="">
        <ResultPage.Card style={{ padding: 8 }}>
          <div className={styles.row}>
            <span onClick={() => nav(`/city/start`)}>{start}</span>
            <LoopOutline onClick={() => dispatch(jh())} />
            <span onClick={() => nav(`/city/end`)}>{end}</span>
          </div>
          <div
            className={styles.row}
            onClick={() => {
              setVisible5(true);
            }}
          >
            {date}
          </div>
          <div className={styles.row}>
            <Button block color="primary" size="large" onClick={()=>nav(`/list?start=${start}&end=${end}&date=${date}&isSpeed=${isSpeed}`)}>
              查询
            </Button>
          </div>
        </ResultPage.Card>
        <Popup
          visible={visible5}
          onMaskClick={() => {
            setVisible5(false);
          }}
          bodyStyle={{
            borderTopLeftRadius: "8px",
            borderTopRightRadius: "8px",
            minHeight: "40vh",
          }}
        >
          <CalendarPickerView
          value={date}
          min={Date.now()}
          max={Date.now()+14*24*60*60*1000}
          onChange={(val)=>{
            dispatch(setDate(val))
            setVisible5(false)
          }} />
        </Popup>
      </ResultPage>
    </div>
  );
}

export default HocLogin(index);
